<?php

namespace app\admin\controller;

use think\Controller;
use think\Request;

class Pub extends Controller
{

    private $obj;

    public function __construct(Request $request = null)
    {
        parent::__construct($request);


        /**
         * 加载这里就退出
         */
        if (session('user', '', 'admin')) {
            session(null, 'admin');
            $this->redirect('pub/login');
        }
        $this->obj = model('User');
    }

    public function ll()
    {

        if ($this->request->isPost()) {

            $data = $this->request->post();
            $result = $this->validate($data, 'User.pub');
            if (true !== $result) {
                return ajax_info($result);
            }

            $user = model('User')->get(['name' => $data['name']]);

            if (!$user) {
                return ajax_info("用户不存在");
            }

            if ($user->password != md5($data['password'] . $user->code)) {
                return ajax_info("密码不正确");
            }

            $data = ['last_login_time' => time()];

            model('User')->updatalosttime($data, $user->id);
            session('user', $user, 'admin');

            return ajax_info("登录成功", 'y');
        }
    }

    public function login()
    {
        return $this->fetch();
    }


}
